Title: SQL W3S (By-BKK) / 035 Exists
Tags: Obsidian_to_Anki

Q: What does the SQL EXISTS operator do?
A: Checks if a subquery returns one or more records

Q: True/False: The EXISTS operator returns TRUE if the subquery finds at least one record
A: True

Q: What is the general use of the EXISTS operator in SQL?
A: To test for the existence of any record in a subquery

Q: Show the basic SQL syntax for using EXISTS
A: SELECT column_name(s) FROM table_name WHERE EXISTS (SELECT column_name FROM table_name WHERE condition)

Q: EXISTS returns TRUE when?
A: When the subquery returns one or more records

Q: What does the following SQL query do?
SELECT SupplierName FROM Suppliers WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID = Suppliers.supplierID AND Price < 20);
A: Lists suppliers who have a product with price less than 20

Q: Give an example of using EXISTS to filter suppliers by product price
A: SELECT SupplierName FROM Suppliers WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID = Suppliers.supplierID AND Price = 22);

Q: What table is commonly used in sample EXISTS queries in W3Schools?
A: Suppliers

Q: EXISTS operator — answer first format
A: Checks for records in a subquery
What SQL operator is this?

Q: True/False: EXISTS can only be used in SELECT statements
A: False

Q: List the two conditions in the sample EXISTS subquery: Products.SupplierID = Suppliers.supplierID AND Price < 20
A: Matching supplier ID and price is less than 20

Q: When does the SQL EXISTS operator return FALSE?
A: When the subquery returns no records

Q: Show an example SQL EXISTS statement for price equal to 22
A: SELECT SupplierName FROM Suppliers WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID = Suppliers.supplierID AND Price = 22);

Q: Why use EXISTS instead of a JOIN?
A: EXISTS is used to test for the existence of related data, not to combine rows